package main

import (
	"context"
	"fmt"
	"time"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/app/server"
	"github.com/cloudwego/hertz/pkg/common/utils"
	"github.com/cloudwego/hertz/pkg/protocol/consts"
	"github.com/hertz-contrib/cors"
)

func main() {
	fmt.Println("startstartstartstart")

	// strings := []string{
	// 	"LIN\\nE4ss\\twww", "line 1", "LINE 2\nLIN3", "LIN\\nE4",
	// }
	// for index, rowData := range strings {
	// 	fmt.Println(index, rowData)
	// 	unq, err := strconv.Unquote(`"` + rowData + `"`)
	// 	// unq, err := strconv.Unquote(rowData)
	// 	if err != nil {
	// 		unq = rowData
	// 	}
	// 	fmt.Println(unq)

	// }

	// jsonData, err := json.Marshal(strings)
	// if err != nil {
	// 	return
	// }
	// fmt.Println(jsonData)

	// casbintest.RunTest()
	// casbintest.RunTest2()
	// casbintest.RunTestMysql()
	// casbintest.TestManyRoles()
	// snakeCasedName("Organi-z1aTion")
	// titleCasedName("ORGANI-Z1A_TION") //
	// server.New(server.WithTransport(standard.NewTransporter))

	// start serve
	h := server.Default(
		server.WithHostPorts("127.0.0.1:9901"),
	)

	h.Use(cors.New(cors.Config{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"PUT", "PATCH", "POST", "GET", "DELETE"},
		AllowHeaders:     []string{"Origin", "Authorization", "Content-Type"},
		AllowCredentials: true,
		AllowOriginFunc:  func(origin string) bool { return true },
		MaxAge:           24 * time.Hour,
	}))

	h.GET("/ping", func(c context.Context, ctx *app.RequestContext) {
		ctx.JSON(consts.StatusOK, utils.H{"message": "pong"})
	})

	h.GET("/subscript", func(c context.Context, ctx *app.RequestContext) {
		fmt.Println("/subscript")
		ctx.JSON(consts.StatusOK, utils.H{
			"openid":      "10",
			"sub_classes": "sub_classes",
			"created_at":  "2002-10-29 18:30:43",
			"updated_at":  "1988-06-13 02:22:30",
		})
	})

	h.Spin()

	// testSprintf("sss2023-05-19")
	// for {
	// 	// 查询数据插入pg库
	// 	fmt.Println("start")
	// 	time.Sleep(1 * time.Second)
	// 	fmt.Println("end")

	// }
}

func test1() {
	// n :=0

}

func testSprintf(b string) string {

	msg := fmt.Sprintf(`
	{
		"first":{
			"value":"%s"
		}
	}
	`, b)
	fmt.Println(msg)
	return msg
}
